﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Linq;

namespace KTX
{
    public partial class frmSinhVien : DevExpress.XtraEditors.XtraForm
    {
        public frmSinhVien()
        {
            InitializeComponent();
        }
        Data.QLKTXEntities db = new Data.QLKTXEntities();

        private void frmSinhVien_Load(object sender, EventArgs e)
        {
            lopBindingSource.DataSource = db.Lop;
            sinhVienBindingSource.DataSource = db.SinhVien;
        }

        private void barThem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var f = new frmThemSinhVien();
            f.ShowDialog();
            sinhVienBindingSource.DataSource = db.SinhVien;
        }

        private void barXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            sinhVienBindingSource.RemoveCurrent();
        }

        private void barSua_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //barSua.PerformClick();
            if (sinhVienBindingSource.Current!=null)
            {
                var f = new frmThemSinhVien((Data.SinhVien)sinhVienBindingSource.Current);
                f.ShowDialog();
            }
        }

        private void barLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            db.SaveChanges();
        }

        private void barIn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void barDong_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Close();
        }

        private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            if (e.Clicks==2 && this.sinhVienBindingSource.Current!=null)
            {
                barSua.PerformClick();
            }
        }

        private void gridLookUpEdit1_EditValueChanged(object sender, EventArgs e)
        {
            sinhVienBindingSource.DataSource = db.SinhVien.Where(p=>p.MaLop==(int)gridLookUpEdit1.EditValue);
        }
    }
}